package com.halcyon.di;

import android.content.Context;


public class ContextManager {

    private DependencyInjectingObjectFactory factory;
    private static ContextManager manager;

    public static ContextManager init(Context context) {
        if (manager == null) {
            manager = new ContextManager(context);
        }
        return manager;
    }

    public static ContextManager getInstance() {
        if (manager == null) {
            throw new RuntimeException("INIT CONTEXT MANAGER FIRST");
        }
        return manager;
    }

    /**
     * 注册所有的对象
     *
     * @param context
     */
    private ContextManager(Context context) {
        factory = new DependencyInjectingObjectFactory();
        //register context
        factory.registerImplementationObject(Context.class, context);
    }

    private <T> void r(Class<T> clazz) {
        factory.registerSingletonImplementationClass(clazz, clazz);
    }

    public <T> T get(Class<T> clazz) {
        return factory.getObject(clazz);
    }
}
